package subject_set.weekly_competition.day10_9;

/**
 * @author haomin
 * @date 2022/10/09 10:22
 **/
public class Num3 {
    class Solution {
        public String robotWithString(String s) {
            StringBuffer p = new StringBuffer();
            StringBuffer t = new StringBuffer();
            for(int i = 0; i < s.length(); ++i){
                char c = s.charAt(i);
                if(t.length() == 0) t.append(c);
                else {
                    if(c <= t.charAt(t.length()-1)){
                        t.append(c);
                    }else {
                        p.append(t.reverse());
                        t = new StringBuffer();
                        t.append(c);
                    }
                }
            }
            p.append(t.reverse());
            return p.toString();
        }
    }
}